import requests

import config
from config import URL


class OrderApi(object):
    def __init__(self):
        self.get_user_order_url = URL + "/api/v1/order/by_user"
        self.get_order_url = URL + "/api/v1/order/{}"
        self.create_order_url = URL + "/api/v1/order"

    def get_user_order(self):
        """获取当前用户的订单信息
        :return 返回数据（dict）有页码“current_page”还有该页的订单详情“data”(list)
        """
        print(config.headers["token"])
        resp = requests.get(url=self.get_user_order_url, headers=config.headers)
        return resp

    def get_order(self, order_id):
        """获取用户某个订单的详细内容
        :return: 返回数据（dict)有“id"于查询路径相同
        """
        resp = requests.get(url=self.get_order_url.format(order_id), headers=config.headers)
        return resp

    def create_order(self, data):
        """创建用户新订单
        :return: 返回数据(dict)有"order_no"订单号以及"order_id"订单编号"pass"是否通过等信息
        """
        resp = requests.post(url=self.create_order_url, headers=config.headers, json=data)
        return resp
